package homework;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestMain {

    /**
     * 文件拷贝
     * @param source 原文件路径
     * @param dist 目标文件路径
     */
    public void copy(String source,String dist){


        String copyIn = "";

        byte[] bso = null;
        byte[] bsi = new byte[1024];
        FileOutputStream fos = null;
        FileInputStream fis = null;


        try {
            //建立流对象
            fis = new FileInputStream(source);
            int n = 0;

            //读取数据
            while ((n = fis.read(bsi)) != -1){
                copyIn += new String(bsi,0,n);
            }
            bso = copyIn.getBytes();
            fos = new FileOutputStream(dist);
            fos.write(bso);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null){
                try {
                    //关闭流
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }




    }


    public static void main(String[] args) {
        TestMain testMain = new TestMain();
        testMain.copy("src/homework/1.jpg","src/atm/1.jpg");

    }

}
